//
//  ThemeLabel.m
//  Project_2_weibo
//
//  Created by 林林 on 16/6/18.
//  Copyright © 2016年 lhn. All rights reserved.
//

#import "ThemeLabel.h"

@implementation ThemeLabel

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //监听通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChanged) name:kThemeChangedNotificationName object:nil];
    }
    return self;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    //监听通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChanged) name:kThemeChangedNotificationName object:nil];
}

- (void)themeChanged {
    
    //从manager中获取颜色
    UIColor *color = [[ThemeManager sharedManager] themeColorWithColorName:self.colorName];
    //设置到label
    self.textColor = color;
    
}

- (void)setColorName:(NSString *)colorName {
    if (_colorName == colorName) {
        return;
    }
    _colorName = [colorName copy];
    [self themeChanged];
}

@end
